package com.clickpaas.timelineofUN.controller;

import com.alibaba.fastjson.JSONObject;
import com.clickpaas.timelineofUN.common.Response.ResponseResult;
import com.clickpaas.timelineofUN.entity.ParamEntity.ReqParamEntity;
import com.clickpaas.timelineofUN.service.UserProjectService;
import com.clickpaas.timelineofUN.utils.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@Api(description = "项目数据查询")
@RestController
@RequestMapping(value = "/search")
public class TimelineOfUNController {
    @Resource
    UserProjectService userProjectService;

    @ApiOperation("根据token区分管理员和用户,管理员查询增加项目方名称")
    @PostMapping(value = "/project")
    public ResponseResult getProjectInfo(HttpServletRequest httpServletRequest, @ApiParam(name ="reqParamEntity" ,value = "请求参数")@RequestBody ReqParamEntity reqParamEntity){
        String token = httpServletRequest.getHeader("tg-token");
        log.info("管理员界面查询开始。。。。入参TOKEN是：【{}】",token);
        long startData = System.currentTimeMillis();
        JSONObject jsonObject = JsonUtil.objToJson(reqParamEntity);
        ResponseResult projectData = userProjectService.getProject(token, jsonObject);
        long endData = System.currentTimeMillis();
        log.info("程序运行时间：【{}ms】",endData-startData);
        return projectData;
    }

    @ApiOperation("查询项目名称以及项目时间线")
    @PostMapping(value = "/proNameTime")
    public ResponseResult getProNameTime(HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader("tg-token");
        log.info("管理员界面查询开始。。。。入参TOKEN是：【{}】",token);
        long startData = System.currentTimeMillis();
        ResponseResult projectData = userProjectService.getProNameTime(token);
        long endData = System.currentTimeMillis();
        log.info("程序运行时间：【{}ms】",endData-startData);
        return projectData;
    }
}
